﻿using Spring.Context;
using Spring.Context.Support;

namespace TinyCms.Infrastructure.Ioc
{
    public class ServiceLocator
    {
        private static readonly ServiceLocator Locator=new ServiceLocator();
        private readonly IApplicationContext _context;
        private ServiceLocator()
        {
            _context= new XmlApplicationContext(@"~Config\Spring.xml");
        }

        public static ServiceLocator Instance
        {
            get { return Locator; }
        }

        public object GetObject(string name)
        {
            return _context.GetObject(name);
        }

        public T GetObject<T>(string name) where T:class 
        {
            return _context.GetObject(name) as T;
        }

        public T GetObject<T>(string name,object[] args)where T:class
        {
            return _context.GetObject(name, args) as T;
        }
    }
}
